package com.frejoys.common.response;

import com.frejoys.common.error.HttpStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class Result<T> {

    @Schema(type = "Integer", name = "code", description = "状态码", required = true, defaultValue = "200")
    private Integer code;

    @Schema(type = "String", name = "msg", description = "状态信息", required = true, defaultValue = "ok")
    private String msg;

    private T data;

    private Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private Result(HttpStatus httpStatus, String msg, T data) {
        this.code = httpStatus.getCode();
        // this.msg = httpStatus.getMsg();
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(HttpStatus.success, "ok", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(HttpStatus.success, "ok", data);
    }

    public static <T> Result<T> success(HttpStatus httpStatus, T data) {
        return new Result<>(httpStatus, "ok", data);
    }

    public static <T> Result<T> success(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> fail() {
        return new Result<>(HttpStatus.fail, "fail", null);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<>(HttpStatus.fail, "fail", data);
    }

    public static <T> Result<T> fail(HttpStatus httpStatus) {
        return new Result<>(httpStatus, "fail", null);
    }

    public static <T> Result<T> fail(HttpStatus httpStatus, T data) {
        return new Result<>(httpStatus, "fail", data);
    }

    public static <T> Result<T> fail(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }


}
